// 引入获取用户信息的请求
import { userProfilesAPI } from "../../request/api"

export default {

    namespaced: true,
    state: {
        cartTotal: 0,
        userInfo: {
            nickName: '昵称',
            coin: "--",
            headImg: require('../../assets/img/userImg.f8bbec5e.png')
        }
    },
    mutations: {
        updateUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal
            state.userInfo = payload.userInfo
        },
        initUserInfo(state) {
            state.cartTotal = 0
            state.userInfo = {
                nickName: '昵称',
                coin: "--",
                headImg: require('../../assets/img/userImg.f8bbec5e.png')
            }
        }
    },
    // 发送请求是异步代码
    actions: {
        async asyncChangeUserInfo(context, payload) {
            let res = await userProfilesAPI();//本来是需要token参数的，但是我们在请求拦截器已经统一处理了
            // console.log("用户信息是:", res);
            context.commit('updateUserInfo', res.data.data)
        }
    }
}